package servlet;

import dao.QuestionDao;
import dao.impl.QuestionDaoImpl;
import entiy.Question;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class QuestionServlet extends HttpServlet {
    QuestionDao questionDao = new QuestionDaoImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String mode = "list";
        String newMode = req.getParameter("mode");
        if (newMode != null && !"".equals(newMode)) {
            mode = newMode;
        }
        if ("list".equals(mode)) {
            List<Question> list = questionDao.selectQuestion();
            req.setAttribute("list", list);
            req.getRequestDispatcher("index.jsp").forward(req, resp);
        }
    }
}
